package de.busschedule.control;

import java.util.List;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import de.busschedule.R;
import de.busschedule.logging.Logger;

public class LineDetailListAdapter extends BaseAdapter{
	Context context;
	List<String> data;
	private static LayoutInflater inflater = null;
	private final String TAG = "LineDetailListAdapter";

	public LineDetailListAdapter(Context context, List<String> data){
		this.context = context;
		this.data = data;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount(){
		return data.size();
	}

	@Override
	public Object getItem(int position){
		return data.get(position);
	}

	@Override
	public long getItemId(int position){
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		//Get layout inflater
		View vi = convertView;
		if(vi == null){
			vi = inflater.inflate(R.layout.list_row_linedetail, null);
		}
		//Get name and time
		String[] s = data.get(position).split("\\#");
		
		if(s.length == 2){
			Resources res = vi.getResources();
			String str = res.getString(R.string.next_departure);
			//append to layout
			TextView nameField = (TextView) vi.findViewById(R.id.list_row_line_detail_name);
			nameField.setText(s[0]);
			TextView timeField = (TextView) vi.findViewById(R.id.list_row_line_detail_time);
			timeField.setText(str + s[1]);
		}
		return vi;
	}
}
